package com.zyh.stream;

import com.zyh.domain.Student;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author zyh
 * @Date 2024/8/16 11:04
 * @Description 过滤收集
 */

public class StreamDemo3 {
    @Test
    public void test3(){
        List<Student> list=new ArrayList<>();
        list.add(new Student("zyh","男",18,170.5));
        list.add(new Student("wy","男",20,140.5));
        list.add(new Student("cxk","女",45,120.5));
        list.add(new Student("dz","女",2,180.5));
        //年龄大于25
        List<Student> list1 = list.stream().filter(item -> item.getAge() > 25).collect(Collectors.toList());
        list1.forEach(System.out::println);
    }
    @Test
    public void test2(){
        String[] strArr={"java","C++","python","javascript","php","vue"};
        //筛选字符串长度大于5的
        List<String> list = Arrays.stream(strArr).filter(item -> item.length() > 5).collect(Collectors.toList());
        list.forEach(System.out::println);
    }
    @Test
    public void test1(){
        List<Integer> list = Arrays.asList(2, 3, 4, 5, 7, 8, 9, 0, 1, 11, 34, 67);
        //筛选所有大于5的元素存入新的集合中
        List<Integer> list1 = list.stream().filter(item -> item > 5).collect(Collectors.toList());
        list1.forEach(System.out::println);
    }
}
